package logic

import (
	"C/Rpc/shop"
	"context"

	"C/Api/internal/svc"
	"C/Api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type EsSearLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewEsSearLogic(ctx context.Context, svcCtx *svc.ServiceContext) *EsSearLogic {
	return &EsSearLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *EsSearLogic) EsSear(req *types.EsSearRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	sear, err := l.svcCtx.ShopRpc.EsSear(l.ctx, &shop.EsSearRequest{FormWord: req.FormWord})
	if err != nil {
		return &types.Response{
			Msg:  err.Error(),
			Code: 500,
			Data: nil,
		}, nil
	}
	return &types.Response{
		Msg:  "搜索成功",
		Code: 200,
		Data: sear,
	}, nil
}
